
				<div class="box span12">
					<div class="box-header" data-original-title>
						<h2><i class="halflings-icon white user"></i><span class="break"></span>新闻列表</h2>
						<div class="box-icon">
							<a href="#" class="btn-setting"><i class="halflings-icon white wrench"></i></a>
							<a href="#" class="btn-minimize"><i class="halflings-icon white chevron-up"></i></a>
							<a href="#" class="btn-close"><i class="halflings-icon white remove"></i></a>
						</div>
					</div>
					<div class="box-content">
                        <div class="row-fluid">
                            <div class="span6">
                                <div id="DataTables_Table_0_length" class="dataTables_length">
                                    <label>
                                        <select size="1" id="sel_page" name="DataTables_Table_0_length" aria-controls="DataTables_Table_0">
                                            <option value="1">1</option>
                                            <option value="3">3</option>
                                            <option value="5">5</option>
                                            <option value="10" selected="selected">10</option>
                                        </select> 选择每页数据条数
                                    </label>
                                </div>
                            </div>
                            <div class="span6">
                                <div class="dataTables_filter" id="DataTables_Table_0_filter">
                                    <label>搜索:
                                        <input type="text" aria-controls="DataTables_Table_0">
                                    </label>
                                </div>
                            </div>
                        </div>
                        <input type="button" name="" id="del_che" value="删除">
                        <input type="button" name="" id="add_news" value="添加">
						<table class="table table-striped table-bordered bootstrap-datatable datatable">
						  <thead>
							  <tr>
                                  <th><input type="checkbox" id="all_che" name="all_che" ></th>
								  <th>id</th>
								  <th>新闻标题</th>
								  <th>新闻内容</th>
                                  <th>新闻类型</th>
                                  <th>图片</th>
                                  <th>作者</th>
                                  <th>发布者</th>
                                  <th>发布时间</th>
								  <th>状态</th>
								  <th>详细</th>
							  </tr>
						  </thead>
						  <tbody>
                            <?php
                            if(!empty($data)):
                            foreach($data as $v) :
                            ?>
							<tr>
                            <td style="width:20px;"><input type="checkbox" name="che" value="<?php echo $v['id']?>" ></td>
								<td class="vid"><?php echo $v['id']?></td>
								<td filed="title" class="center db_edit"><?php echo $v['title']?></td>
								<td filed="content" class="center db_edit"><?php echo $v['content']?></td>
                                <td class="center"><?php echo $v['name']?></td>
                                <td class="center"><img src="<?php echo empty($v['url'])? 'nod.jpg':$v['url'] ?>" width="50" height="50" alt=""></td>
                                <td class="center"><?php echo $v['author']?></td>
                                <td class="center"><?php echo $v['send_user']?></td>
                                <td class="center"><?php echo $v['create_time']?></td>
                                <td filed="status" class="center">
                                    <span class="label label-success db_rev"><?php echo ($v['status']) ? '<a id="yes" class="halflings-icon ok"></a>':'<a id="no" class="halflings-icon remove"></a>'?></span>
                                </td>
								<td class="center">
									<a class="btn btn-success" href="#">
										<i class="halflings-icon white zoom-in"></i>
									</a>
									<a class="btn btn-info" href="index.php?c=news&a=edit&admin=1&id=<?php echo $v['id']?>">
										<i class="halflings-icon white edit"></i>
									</a>
									<a class="btn btn-danger" onclick="return confirm('真的要删除？')" href="index.php?c=news&a=del&admin=1&id=<?php echo $v['id']?>">
										<i class="halflings-icon white trash"></i>
									</a>
								</td>
							</tr>
                            <?php
                            endforeach;endif;
                            ?>
						  </tbody>
					  </table>
                      <form action="index.php" class="form-horizontal" method="get">
                        <input type="hidden" name="c"  value="news" >
                        <input type="hidden" name="a"   value="list">
                        <input type="hidden" name="admin" value="1"  >
                      <div class="span12 center">
                        <div class="dataTables_paginate paging_bootstrap pagination">
                            <ul id="news_ul">

                                <?php echo $pages ?>

                                <!-- <li>跳到 <input type="text" name="p"  value="<?php echo $cur_page ?>" >
                                <li>
                                 <button type="submit" class="btn btn-primary" >确定</button>

                                </li> -->

                            </ul>
                        </div>
                         </form>
                    </div>
					</div>
				</div><!--/span-->
                <script src="resources/admin/js/jquery-1.9.1.min.js"></script>
                <script  type="text/javascript">

                    $(function(){
                        //添加一行
                        $('#add_news').click(function(event) {

                            var news_cate=new Array();
                            $.ajax({
                                url: 'index.php?c=cate&a=add&admin=1',
                                type: 'GET',
                                dataType:'json',
                                //data: {},
                                async: true,
                                success:function(data){
                                /* Act on the event */
                                var html='';
                                    html+='<tr>';
                                    html+='<td style="width:20px;"></td>';
                                    html+='<td></td>';
                                    html+='<td filed="title" class="center db_edit"><input type="text" id="title" name="" value=""></td>';
                                    html+='<td filed="content" class="center db_edit"><textarea name=""class="content"></textarea></td>';
                                    html+='<td class="center sel_list"><select class="sel cate_id" id="cate_id" name="" style="width:100px;">';
                                    html+='<option value="0"  selected="selected">顶级分类</option>';
                                    for(i in data){
                                         html+='<option value="'+data[i]['id']+'">'+data[i]['name']+'</option>';
                                    }
                                    html+='</select></td>';
                                    html+='<td class="center"><img src="" width="50" height="50" alt=""></td>';
                                    html+='<td class="center"><input type="text" id="author" name="" value=""></td>';
                                    html+='<td class="center"></td>';
                                    html+='<td class="center"></td>';
                                    html+='<td filed="status" class="center">';
                                    html+='<span class="center db_rev"><select name="" id="status" style="width:80px;"><option value="1">通过</option><option value="0">未通过</option></select></span></td>';
                                    html+='<td class="center">';
                                    html+='<a class="btn btn-info" href="#" id="save">';
                                    html+='<i class="halflings-icon white edit"></i>';
                                    html+='</a>';
                                    html+='<a class="btn btn-danger" id="remo" href="#">';
                                    html+='<i class="halflings-icon white trash"></i>';
                                    html+='</a>';
                                    html+='</td>';
                                    html+='<td><input type="hidden" id="add_save" value="1"></td>';
                                    html+='</tr>';
                                    $('tbody').prepend(html);
                                    $('.sel_list').on('change','select',function(event) {
                                    var id=$(this).val();
                                    //移除该标签后面同级标签
                                    $(this).nextAll().remove();
                                    //获取option文本
                                    //var p=$(this).find('option:selected').text();
                                    //获取option下标
                                    //$(this).get(0).selectedIndex
                                    if($(this).get(0).selectedIndex==0){
                                        return false;
                                    }
                                    /* Act on the event */
                                    $.ajax({
                                        type: 'GET',
                                        url: 'index.php?c=cate&a=add&admin=1&id='+id,
                                        dataType:'json',
                                        //data: {},
                                        success:function(data){
                                            var html='';
                                            html+='<div><select class="sel cate_id" style="width:100px" size="1" name="pid" aria-controls="DataTables_Table_0">';
                                            html+='<option value="'+id+'">上一级</option>';
                                                 for (i in data){
                                                html+='<option value="'+data[i].id+'">'+data[i].name+'</option>';
                                                }
                                                html+='</select></div>';

                                            //追加
                                            $('.sel_list').append(html);
                                        }
                                    })

                        })

                                }

                        })
                    });
                    //移除增加的行
                    $('tbody').on('click','#remo',function(event){
                        $(this).parents('tr').remove();

                    })
                    //保存
                    $('tbody').on('click','#save',function(event){

                        var title=$('#title').val();
                        var content=$('.content').val();
                        var cate_id=$('.cate_id:last').val();
                        var author=$('#author').val();
                        var status=$('#status').val();
                        var add_save=$('#add_save').val();
                        $.ajax({
                            url: 'index.php?c=news&a=add&admin=1',
                            type: 'GET',
                            //dataType: '',
                            data: {
                                'title':title,
                                'content':content,
                                'cate_id':cate_id,
                                'author':author,
                                'status':status,
                                'add_save':add_save
                            },
                            success:function(data){
                                if(data>0){
                                        alert('添加成功');
                                        window.location.reload();
                                    }else{
                                        alert('添加失败');
                                    }

                            }
                        })


                    })

                        //批量删除
                        $('#del_che').click(function(event) {
                            var i=0;
                            var a='';
                            /* Act on the event */
                            $('tbody :checkbox').each(function() {
                                 /* iterate through array or object */

                                 if($(this).is(':checked')){
                                    a+=$(this).val();
                                    a+=',';
                                 }

                            });
                            $.ajax({
                                url: 'index.php?c=news&a=del&admin=1',
                                type: 'POST',
                                //dataType:'json',
                                data: {'arr_id': a},
                                success:function(data){
                                    //alert(data);
                                    if(data>0){
                                        alert('删除成功');
                                        $('tbody :checkbox:checked').parents('tr').remove();
                                    }else{
                                        alert('删除失败');
                                    }
                                }
                            })


                        });
                        //批量选中
                        $('thead').on('click','#all_che',function(event) {
                            /* Act on the event */
                            if($(this).is(':checked')){
                                $('tbody :checkbox').prop('checked',true);
                                $('tbody :checkbox').parent().addClass('checked');
                            }else{
                                $('tbody :checkbox').prop('checked',false);
                                $('tbody :checkbox').parent().removeClass('checked');
                            }

                        });
                        //无刷新翻页
                         //$('#news_ul li').click(function(){
                         //动态绑定事件
                        $('#news_ul').on('click','li',function(){
                            var url= $(this).find('a').attr('href');
                            $.ajax({
                               type: "GET",//请求类型
                               url: url,//请求的地址
                               dataType:'json',//数据类型
                               //data: "name=John&location=Boston",//将数据提交到后台
                               //async:true;//是否同步
                               //回调函数
                            success: function(data){
                                var html='';
                                    html= list_page(data);
                                $('tbody').html(html);
                                $('#news_ul').html(data.pages);

                                    dbclick();
                               }
                            })
                            return false;
                        });

                        dbclick();
                        //修改每页数据条数
                        $('#sel_page').change(function(event) {
                            /* Act on the event */
                            var page=$(this).val();
                            $.ajax({
                                type:'GET',
                                url:'index.php?c=news&a=list&page='+page+'&admin=1',
                                dataType:'json',
                                data:{
                                    'page':page
                                },
                                success: function(data){

                                    var html= list_page(data);
                                //alert(data.data);
                                $('tbody').html(html);
                                $('#news_ul').html(data.pages);

                                    dbclick();
                               }
                            })

                        });
                    })
                        //双击修改新闻内容函数
                    function dbclick(){
                        $('tbody tr').on('dblclick','.db_edit',function() {
                            /* Act on the event */
                            var txt=$(this).text();
                            var inp='<input class="db_inp" type="text" value='+txt+'>';
                            $(this).html(inp);
                            $(".db_inp").focus();
                            $('.db_inp').blur(function () {

                                var inp_txt=$(this).val();
                                var id = $(this).parent().parent().find('.vid').text();
                                var filed=$(this).parent().attr('filed');
                                $(this).parent().text(inp_txt);
                                    if(inp_txt!=txt){
                                    $.ajax({
                                        type:'POST',
                                        url:'index.php?c=news&a=edit&admin=1',
                                        data:{
                                            'id':id,
                                            'val':inp_txt,
                                            'filed':filed
                                        },
                                        success:function(res){
                                                if(res>0){
                                                    alert('新闻修改成功');
                                                }else{
                                                    alert('新闻修改失败');
                                                }
                                        }
                                    })
                                }
                            });
                        });
                        //新闻审核
                        $('tbody tr').on('click','.db_rev',function() {
                            /* Act on the event */
                            var a=$(this).find('a').attr('id');
                            var val=0;
                                if(a=='yes'){
                                    val=0;
                                }else if(a=='no'){
                                    val=1;
                                }else{
                                    val=-1;
                                }
                                var obj =  $(this);
                                 var id = $(this).parent().parent().find('td:first').text();
                                 var filed=$(this).parent().attr('filed');
                                    $.ajax({
                                        type:'POST',
                                        url:'index.php?c=news&a=edit&admin=1',
                                        data:{
                                            'id':id,
                                            'val':val,
                                            'filed':filed
                                        },
                                        success:function(res){
                                                if(res>0){
                                                    alert('新闻审核成功');
                                                    if(val==1){
                                                        obj.html('<a id="yes" class="halflings-icon ok"></a>');
                                                    }else{
                                                        obj.html('<a id="no" class="halflings-icon remove"></a>');
                                                    }


                                                }else{
                                                    alert('新闻审核失败');
                                                }
                                        }
                                    })
                        });

                    }
                    //每页数据加载函数
                    function list_page(data){

                        var json=data.data;
                                var html='';
                                for(i in json){
                                    html+='<tr>';
                                    html+='<td style="width:20px;"><input type="checkbox" name="che" value="'+json[i].id+'" ></td>';
                                    html+='<td>'+json[i].id+'</td>';
                                    html+='<td filed="title" class="center db_edit">'+json[i].title+'</td>';
                                    html+='<td filed="content" class="center db_edit">'+json[i].content+'</td>';
                                    html+='<td class="center">'+json[i].name+'</td>';
                                    var n =(json[i].url=='')?'nod.jpg':json[i].url;
                                    html+='<td class="center"><img src="'+n+'" width="50" height="50" alt=""></td>';
                                    html+='<td class="center">'+json[i].author+'</td>';
                                    html+='<td class="center">'+json[i].send_user+'</td>';
                                    html+='<td class="center">'+json[i].create_time+'</td>';
                                    html+='<td filed="status" class="center">';
                                    var status='';
                                    if(json[i].status=='1'){
                                        status='<a id="yes" class="halflings-icon ok"></a>';
                                    }else{
                                        status='<a id="no" class="halflings-icon remove"></a>';
                                    }
                                    html+='<span class="label label-success db_rev">'+status+'</span></td>';
                                    html+='<td class="center">';
                                    html+='<a class="btn btn-success" href="#">';
                                    html+='<i class="halflings-icon white zoom-in"></i></a>';
                                    html+='<a class="btn btn-info" href="index.php?c=news&a=edit&admin=1&id='+json[i].id+'">';
                                    html+='<i class="halflings-icon white edit"></i>';
                                    html+='</a>';
                                    html+='<a class="btn btn-danger" onclick="return confirm('+'真的要删除？'+ ')" ';
                                    html+='href="index.php?c=news&a=del&admin=1&id='+json[i].id+'">';
                                    html+='<i class="halflings-icon white trash"></i>';
                                    html+='</a>';
                                    html+='</td>';
                                    html+='</tr>';
                                };

                                    return html;
                    }
                </script>